package com.project.controller;

import com.project.dto.OrderDto;
import com.project.service.ICinemaDao;
import com.project.dto.CinemaDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author(王思翰)
 * @Description(类的描述)
 * @Date(创建时间) 2021/9/7 16:37
 */
@RestController
@RequestMapping("cinema")
public class CinemaController {
    @Autowired
    ICinemaDao cinemaDao;

    @GetMapping("findByAll")
    public List<CinemaDto> findByAll(){
        return cinemaDao.findByAll();
    }

    @GetMapping("updateNumber/{id}")
    public boolean updateNumber(@PathVariable("id") int id){
        CinemaDto cinemaDto=cinemaDao.findById(id);
        if (cinemaDto.getNumber()==0){
            return false;
        }
        cinemaDao.updateNumber(id);
        return true;
    }

    @GetMapping("addOrder/{id}/{name}/{money}")
    public String addOrder(@PathVariable("id") int id
            ,@PathVariable("name") String name
            ,@PathVariable("money") int money){
        System.out.println("添加后台电影订单");
        OrderDto orderDto=new OrderDto();
        orderDto.setCid(id);
        orderDto.setCname(name);
        orderDto.setCmoney(money);
        cinemaDao.addOrder(orderDto);
        return "添加订单成功";
    }
}
